#include "_queue_SimpleQueue.h"
#include "pika_hal_deque.h"




void _queue_SimpleQueue___init__(PikaObj *self){
    pika_hal_deque* que = pika_hal_deque_create();
    if (que == NULL){
        obj_setErrorCode(self, PIKA_RES_ERR_INSUFFICIENT_RESOURCE);
        obj_setSysOut(self, "[error] not enough memory.");
    }

    obj_setPtr(self, "_queue", que);
    
}
void _queue_SimpleQueue_put(PikaObj *self, Arg* item){
    pika_hal_deque* que = obj_getPtr(self, "_queue");
    int result = pika_hal_deque_appendTail(que, (void*)arg_copy(item));
    if (result != 0){
        obj_setErrorCode(self, PIKA_RES_ERR_SIGNAL_EVENT_FULL);
        obj_setSysOut(self, "queue is full.");
    }
}

Arg* _queue_SimpleQueue_get(PikaObj *self){
    pika_hal_deque* que = obj_getPtr(self, "_queue");
    Arg* item;
    int result = pika_hal_deque_popHead(que, (void**)&item);
    if (result == 0){
        return item;
    }
    else{
        obj_setErrorCode(self, PIKA_RES_ERR_SIGNAL_EVENT_EMPTY);
        obj_setSysOut(self, "queue is empty.");
        return NULL;
    }

}

int _queue_SimpleQueue_qsize(PikaObj *self){
    pika_hal_deque* que = obj_getPtr(self, "_queue");
    return pika_hal_deque_getCount(que);
}

pika_bool _queue_SimpleQueue_empty(PikaObj *self){
    pika_hal_deque* que = obj_getPtr(self, "_queue");
    return pika_hal_deque_isEmpty(que) ? pika_true : pika_false;
}
void _queue_SimpleQueue___del__(PikaObj *self){
    pika_hal_deque* que = obj_getPtr(self, "_queue");
    pika_hal_deque_deinit(que);
}

